package com.example.wumeng.spinner;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Spinner;

import java.util.ArrayList;
import java.util.List;

public class SecondActivity extends AppCompatActivity {

    private Spinner spinner;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second);

        // 初始化控件
        spinner = findViewById(R.id.spinner2);

        // 建立数据源
        List<Person> persons = new ArrayList<>();
        persons.add(new Person("张三","上海"));
        persons.add(new Person("李四","上海"));
        persons.add(new Person("王五","北京"));
        persons.add(new Person("赵六","广州"));

        // 建立Adapter绑定数据源
        MyAdapter adapter = new MyAdapter(persons,this);

        spinner.setAdapter(adapter);
    }
}
